/*
 *  StochasticSoundObject000Tester.cpp
 *  SoundController0002
 *
 *  Created by jiro on 10/07/17.
 *  Copyright 2010 jiro music. All rights reserved.
 *
 */

#include "StochasticSoundObject000Tester.h"
#include "TestCommon.h"

namespace sc
{

	void StochasticSoundObject000Tester::TestAll()
	{
		std::cout << "StochasticSoundObject000Tester, start\n";
		Test_005();
		Test_000();
		Test_0001();
		Test_001();
		Test_002();
		Test_003();
		Test_004();
		std::cout << "StochasticSoundObject000Tester, end\n";
	}

	void StochasticSoundObject000Tester::Test_000()
	{
		std::cout << "Test_000\n";
		
		StochasticSoundObject000_32 obj( 5, 1 );

		std::vector< AudioElement32 > elements1;
		obj.GetAudioElememts( 0, elements1 );

		AudioRecorder32 recorder( 2, 1 );
		for ( size_t i = 0; i < elements1.size(); i++ )
		{
			recorder.Record( 0, 0, elements1[ i ] );
			recorder.Record( 1, 0, elements1[ i ] );
		}

		Play( recorder, player );
	}

	void StochasticSoundObject000Tester::Test_0001()
	{
		std::cout << "Test_0001\n";
		
		StochasticSoundObject000_32 obj( 5, 5 );

		std::vector< AudioElement32 > elements1;
		std::vector< AudioElement32 > elements2;
		obj.GetAudioElememts( 0, elements1 );
		obj.GetAudioElememts( 0, elements2 );

		AudioRecorder32 recorder( 2, 1 );
		for ( size_t i = 0; i < elements1.size(); i++ )
		{
			recorder.Record( 0, 0, elements1[ i ] );
			recorder.Record( 1, 0, elements2[ i ] );
		}
		
		Play( recorder, player );
		
	}

	void StochasticSoundObject000Tester::Test_001()
	{
		std::cout << "Test_001\n";
		
		StochasticSoundObject000_32 obj1( 5, 0.5 );
		StochasticSoundObject000_32 obj2( 5, 5 );
		
		std::vector< AudioElement32 > elements1;
		std::vector< AudioElement32 > elements2;
		obj1.GetAudioElememts( 0, elements1 );
		obj2.GetAudioElememts( 0, elements2 );

		AudioRecorder32 recorder( 2, 1 );
		for ( size_t i = 0; i < elements1.size(); i++ )
		{
			recorder.Record( 0, 0, elements1[ i ] );
		}
		for ( size_t i = 0; i < elements2.size(); i++ )
		{
			recorder.Record( 1, 0, elements2[ i ] );
		}

		Play( recorder, player );
	}

	void StochasticSoundObject000Tester::Test_002()
	{
		std::cout << "Test_002\n";
		
		StochasticSoundObject000_32 obj1( 5, 0.5 );
		StochasticSoundObject000_32 obj2( 5, 5 );
		StochasticSoundObject000_32 obj3( 5, 0.15 );
		StochasticSoundObject000_32 obj4( 5, 15 );
		
		std::vector< AudioElement32 > elements[ 4 ];
		obj1.GetAudioElememts( 0, elements[ 0 ] );
		obj2.GetAudioElememts( 0, elements[ 1 ] );
		obj3.GetAudioElememts( 0, elements[ 2 ] );
		obj4.GetAudioElememts( 0, elements[ 3 ] );
		
		AudioRecorder32 recorder( 2, 1 );
		for ( int i = 0; i < 4; i++ )
		{
			for ( int j = 0; j < elements[ i ].size(); j++ )
			{
				recorder.Record( i % 2, 0, elements[ i ][ j ] );
			}
		}

		Play( recorder, player );

	}

	void StochasticSoundObject000Tester::Test_003()
	{
		std::cout << "Test_003\n";
		StochasticSoundObject000_32 obj1( 5, 0.5 );
		StochasticSoundObject000_32 obj2( 5, 5 );
		StochasticSoundObject000_32 obj3( 5, 0.15 );
		StochasticSoundObject000_32 obj4( 5, 15 );
		
		std::vector< AudioElement32 > elements[ 4 ];
		obj1.GetAudioElememts( 0, elements[ 0 ] );
		obj2.GetAudioElememts( 1, elements[ 1 ] );
		obj3.GetAudioElememts( 2, elements[ 2 ] );
		obj4.GetAudioElememts( 0, elements[ 3 ] );

		AudioRecorder32 recorder( 2, 1 );
		for ( int i = 0; i < 4; i++ )
		{
			for ( int j = 0; j < elements[ i ].size(); j++ )
			{
				recorder.Record( i % 2, 0, elements[ i ][ j ] );
			}
		}

		Play( recorder,player );
	}

	void StochasticSoundObject000Tester::Test_004()
	{
		std::cout << "Test_004\n";
		StochasticSoundObject000_32 obj1( 5, 0.15 );

		std::vector< AudioElement32 > elements[ 4 ];
		obj1.GetAudioElememts( 0, elements[ 0 ] );
		obj1.GetAudioElememts( 0, elements[ 1 ] );
		obj1.GetAudioElememts( 0, elements[ 2 ] );
		obj1.GetAudioElememts( 0, elements[ 3 ] );

		AudioRecorder32 recorder( 2, 1 );
		for ( int i = 0; i < 4; i++ )
		{
			for ( int j = 0; j < elements[ i ].size(); j++ )
			{
				recorder.Record( i % 2, 0, elements[ i ][ j ] );
			}
		}

		Play( recorder, player );
	}

	void StochasticSoundObject000Tester::Test_005()
	{
		std::cout << "Test_005\n";

		const int count = 8;
		for ( int k = 1; k < 4; k++ )
		{
			AudioRecorder32 recorder( 2, 1 );
			StochasticSoundObject000_32 obj[ count ];
			std::vector< AudioElement32 > elements[ count ];
			for ( int i = 0; i < count; i++ )
			{
				obj[ i ] = StochasticSoundObject000_32( 32, k + 1.0 / ( i + 1 ) );
				obj[ i ].GetAudioElememts( 0 , elements[ i ] );
				for ( int j = 0; j < elements[ i ].size(); j++ )
				{
					recorder.Record( i % 2, 0, elements[ i ][ j ] );
				}
			}
			if ( k == 2 )
			{
				recorder.OutputAudioFile( 'WAVE', "/Users/jiro/a.wav" );
			}
			Play( recorder, player );		
		}
	}
}